package com.quanyan.stadium.transfer.impl;

import com.quanyan.stadium.constants.GameConstants;
import com.quanyan.stadium.entity.vo.GameSystem;
import com.quanyan.stadium.enums.GameCategoryConfigEnum;
import com.quanyan.stadium.enums.GameGradeLevelConfigEnum;
import com.quanyan.stadium.enums.GameSystemConfigEnum;
import com.quanyan.stadium.enums.PayTypeEnum;
import com.quanyan.stadium.transfer.GameConfigTransfer;
import com.quanyan.statium.api.req.GameCategory;
import com.quanyan.statium.api.req.GameGradeLevel;
import com.quanyan.statium.api.req.PayTypeModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * Created by xiaoxiao on 17/2/15.
 *
 *
 * 存放一些基本的方法封装
 */
@Service
public class GameConfigServiceImpl implements GameConfigTransfer {


    private final static Logger logger = LoggerFactory.getLogger(GameConfigServiceImpl.class);

    @Override
    public PayTypeModel getPayTypeModelById(Integer id) {
        PayTypeModel payTypeModel = new PayTypeModel();
        switch (id) {
            case 0:
                payTypeModel.setPayType((byte) PayTypeEnum.CONFIG_PAY_TYPE_ONLINE.getId());
                payTypeModel.setType((byte) PayTypeEnum.CONFIG_PAY_TYPE_ONLINE.getType());
                payTypeModel.setName(PayTypeEnum.CONFIG_PAY_TYPE_ONLINE.getLabel());
                break;
            case 1:
                payTypeModel.setPayType((byte) PayTypeEnum.CONFIG_PAY_TYPE_AA.getId());
                payTypeModel.setType((byte) PayTypeEnum.CONFIG_PAY_TYPE_AA.getType());
                payTypeModel.setName(PayTypeEnum.CONFIG_PAY_TYPE_AA.getLabel());
                break;
            case 2:
                payTypeModel.setPayType((byte) PayTypeEnum.CONFIG_PAY_TYPE_FAIL.getId());
                payTypeModel.setType((byte) PayTypeEnum.CONFIG_PAY_TYPE_FAIL.getType());
                payTypeModel.setName(PayTypeEnum.CONFIG_PAY_TYPE_FAIL.getLabel());
                break;
            case 3:
                payTypeModel.setPayType((byte) PayTypeEnum.CONFIG_PAY_TYPE_ME.getId());
                payTypeModel.setType((byte) PayTypeEnum.CONFIG_PAY_TYPE_ME.getType());
                payTypeModel.setName(PayTypeEnum.CONFIG_PAY_TYPE_ME.getLabel());
                break;
            case 4:
                payTypeModel.setPayType((byte) PayTypeEnum.CONFIG_PAY_TYPE_FREE.getId());
                payTypeModel.setType((byte) PayTypeEnum.CONFIG_PAY_TYPE_FREE.getType());
                payTypeModel.setName(PayTypeEnum.CONFIG_PAY_TYPE_FREE.getLabel());
                break;
            default:
                logger.debug("支付不存在");
        }
        return payTypeModel;
    }

    @Override
    public GameCategory getGameCategoryById(Integer id) {
        GameCategory gameCategory = new GameCategory();
        switch(id) {
            case 4:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V3.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V3.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V3.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V3.getMaxNum());
                break;
            case 5:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V4.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V4.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V4.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V4.getMaxNum());
                break;
            case 6:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V5.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V5.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V5.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V5.getMaxNum());
                break;
            case 1:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V7.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V7.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V7.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V7.getMaxNum());
                break;
            case 2:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V9.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V9.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V9.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V9.getMaxNum());
                break;
            case 3:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V11.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V11.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V11.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V11.getMaxNum());
                break;

            case 7:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW_ONLY.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW_ONLY.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW_ONLY.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW_ONLY.getMaxNum());
                break;
            case 8:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MALE_DOUBLE.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MALE_DOUBLE.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MALE_DOUBLE.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MALE_DOUBLE.getMaxNum());
                break;
            case 9:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MIXED_DOUBLE.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MIXED_DOUBLE.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MIXED_DOUBLE.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MIXED_DOUBLE.getMaxNum());
                break;
            case 10:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_FEMALE_DOUBLE.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_FEMALE_DOUBLE.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_FEMALE_DOUBLE.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_FEMALE_DOUBLE.getMaxNum());
                break;
            case 11:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_ALL.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_ALL.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_ALL.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_ALL.getMaxNum());
                break;
            case 12:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MALE_ONLY.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MALE_ONLY.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MALE_ONLY.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_MALE_ONLY.getMaxNum());
                break;
            case 14:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW_DOUBLE.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW_DOUBLE.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW_DOUBLE.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW_DOUBLE.getMaxNum());
                break;
            case 16:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_FEMALE_ONLY.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_FEMALE_ONLY.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_FEMALE_ONLY.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_FEMALE_ONLY.getMaxNum());
                break;
            case 18:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V6.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V6.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V6.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V6.getMaxNum());
                break;
            case 19:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V8.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V8.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V8.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_V8.getMaxNum());
                break;
            default:
                gameCategory.setName(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW.getLabel());
                gameCategory.setGameCategoryType(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW.getId());
                gameCategory.setMinNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW.getMinNum());
                gameCategory.setMaxNum(GameCategoryConfigEnum.CONFIG_GAME_CATEGORY_NOT_KNOW.getMaxNum());
        }
        return gameCategory;
    }

    @Override
    public GameSystem getGameSystemById(Integer id) {
        GameSystem gameSystem = new GameSystem();
        switch (id) {
            case 1:
                gameSystem.setName(GameSystemConfigEnum.CONFIG_GAME_TYPE_WASHED.getLabel());
                gameSystem.setGameSystemType(1);
                break;
            case 2:
                gameSystem.setName(GameSystemConfigEnum.CONFIG_GAME_TYPE_CIRCLE.getLabel());
                gameSystem.setGameSystemType(2);
                break;
            case 3:
                gameSystem.setName(GameSystemConfigEnum.CONFIG_GAME_TYPE_MIXED.getLabel());
                gameSystem.setGameSystemType(3);
                break;
            case 4:
                gameSystem.setName(GameSystemConfigEnum.CONFIG_GAME_TYPE_SWISS.getLabel());
                gameSystem.setGameSystemType(4);
                break;
            case 5:
                gameSystem.setName(GameSystemConfigEnum.CONFIG_GAME_TYPE_UNSET_RULE.getLabel());
                gameSystem.setGameSystemType(5);
                break;
            case 6:
                gameSystem.setName(GameSystemConfigEnum.CONFIG_GAME_TYPE_PK.getLabel());
                gameSystem.setGameSystemType(6);
                break;
            case 7:
                gameSystem.setName(GameSystemConfigEnum.CONFIG_GAME_TYPE_EIGHT_RULE.getLabel());
                gameSystem.setGameSystemType(7);
                break;
            default:
                logger.debug("赛制不存在");
        }
        return gameSystem;
    }

    @Override
    public GameGradeLevel getGameGradeLevelById(int categoryId, Integer id) {
        GameGradeLevel gameGradeLevel = new GameGradeLevel();
        if (id.intValue() == 0) {
            gameGradeLevel.setGradeLevelType(GameGradeLevelConfigEnum.CONFIG_GAME_GRADE_LEVEL_0.getId());
            gameGradeLevel.setDesc(GameGradeLevelConfigEnum.CONFIG_GAME_GRADE_LEVEL_0.getName());
            gameGradeLevel.setScore(GameGradeLevelConfigEnum.CONFIG_GAME_GRADE_LEVEL_0.getLabel());
        }else {
            double s = new BigDecimal((1.0+id)/2.0).setScale(1).doubleValue();
            gameGradeLevel.setGradeLevelType(id);
            gameGradeLevel.setDesc(transferMsg(categoryId, s));
            gameGradeLevel.setScore(s);
        }
        return gameGradeLevel;
    }

    private String transferMsg(int categoryId, double level){
        String msg = level+"";
        if (categoryId != GameConstants.CATEGORY_ID_TENNIS) {
            msg = (int)level+"级";
        }
        return msg;
    }

    @Override
    public Integer getLevelIdByLevelAndCateId(Double level) {
        if (level > 0) {
            return (int)(level * 2 - 1);
        }
        return 0;
    }
}
